package com.adt.studioms.om;

import java.util.ArrayList;
import java.util.List;

import com.asao.baseware.core.om.Entity;

public abstract class Transaction<TXD extends TxDetail> extends Entity {
    public static final String PAYMENT = "PAYMENT";
    public static final String TRADING = "TRADING";

    String code;
    Operator operator;
    String description;
    List<TXD> details;

    public Transaction() {
        details = new ArrayList<TXD>();
    }
    
    public abstract String getType();
    
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Operator getOperator() {
        return operator;
    }

    public void setOperator(Operator operator) {
        this.operator = operator;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<TXD> getDetails() {
        return details;
    }

    public void setDetails(List<TXD> details) {
        this.details = details;
    }
    
    public abstract TXD createDetail();
    
    public void addDetail(TXD detail) {
        if (detail != null) {
            details.add(detail);
            detail.setTransaction(this);
        }
    }

    public void removeDetail(TXD detail) {
        if (detail != null) {
            details.remove(detail);
            detail.setTransaction(null);
        }
    }
}
